<template>
  <div class="dataVisualize-box">
    <!--上半-->
    <div class="card top-box">
      <h1 class="top-title">数据概览</h1>
      <el-divider/>
      <div class="top-content">
        <el-row :gutter="40">

          <!--大数据-->
          <el-col class="mb40" :xs="24" :sm="12" :md="12" :lg="6" :xl="6">
            <div class="item-left sle">
              <span class="left-title">设备总数</span>
              <div class="img-box">
                <img src="./images/book-sum.png" alt="" />
              </div>
              <span class="left-number">{{total}}</span>
            </div>
          </el-col>

          <!--小数据-->
          <el-col class="mb40" :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
            <div class="item-center">
              <div class="gitee-traffic traffic-box">
                <div class="traffic-img">
                  <img src="./images/add_person.png" alt="" />
                </div>
                <span class="item-value">26 ℃</span>
                <span class="traffic-name sle">室内温度</span>
              </div>

              <div class="gitHub-traffic traffic-box">
                <div class="traffic-img">
                  <img src="./images/add_team.png" alt="" />
                </div>
                <span class="item-value">50%</span>
                <span class="traffic-name sle">室内湿度</span>
              </div>

              <div class="today-traffic traffic-box">
                <div class="traffic-img">
                  <img src="./images/today.png" alt="" />
                </div>
                <span class="item-value">{{activeNum}}</span>
                <span class="traffic-name sle">正在运行设备</span>
              </div>

              <div class="yesterday-traffic traffic-box">
                <div class="traffic-img">
                  <img src="./images/book_sum.png" alt="" />
                </div>
                <span class="item-value">171W/h</span>
                <span class="traffic-name sle">平均运行功率</span>
              </div>
            </div>
          </el-col>

          <!--饼图-->
          <el-col class="mb40" :xs="24" :sm="24" :md="24" :lg="10" :xl="10">
            <div class="item-right">
              <div class="echarts-title">各家居运行时长（单位：小时）</div>
              <div class="book-echarts">
                <pie></pie>
              </div>
            </div>
          </el-col>

        </el-row>
      </div>
    </div>

    <!--折线图-->
    <div class="card bottom-box">
      <div class="bottom-title">数据报表</div><br/><br/>
      <hr/>
      <div class="curve-echarts">
        <line-chart/>
      </div>
    </div>

  </div>
</template>

<script>
import pie from '@/views/dashboard/PieChart';
import lineChart from '@/components/echarts/LineComponent';
import {listMachine} from "@/api/machine/machine";

export default {
  components: {
    pie,
    lineChart,
  },
  data(){
    return{
      activeNum: 0,
      total: null,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        machineName: null,
        machineState: null,
        areaId: null
      },
      machineList: [],
    }
  },
  created() {
    this.getList();

  },
  methods: {
    getList() {
      listMachine(this.queryParams).then(response => {
        this.machineList = response.rows;
        console.log(this.machineList);
        this.total = response.total;

        for(let i = 0;i < this.total;i++){
          let machine = this.machineList[i];
          console.log(machine);
          if(machine.machineState === 1) this.activeNum++;
        }
      });
    },
    getActive(){
      let activeNum = 0;
      for(const machine in this.machineList){
        if(machine.machineState === 1) activeNum = activeNum+1;
      }
      console.log(activeNum)
      this.activeNum = activeNum;
    }
  }
}

</script>

<style scoped lang="scss">
.dataVisualize-box {
  background-color: #fff;

  .top-box {
    background-color: #fff;
    box-sizing: border-box;
    padding: 25px 40px 0;
    margin: 10px 10px 10px 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    .top-title {
      margin-bottom: 10px;
      font-family: DIN;
      font-size: 18px;
      font-weight: bold;
    }
    .top-content {
      margin-top: 10px;
      .item-left {
        box-sizing: border-box;
        height: 395px;
        padding: 40px 0 30px 30px;
        overflow: hidden;
        color: #ffffff;
        background: url("./images/book-bg.png") 50%;
        background-size: cover;
        border-radius: 20px;
        .left-title {
          font-family: DIN;
          font-size: 20px;
        }
        .img-box {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 90px;
          height: 90px;
          margin: 40px 0 20px;
          background-color: #ffffff;
          border-radius: 20px;
          box-shadow: 0 10px 20px rgb(0 0 0 / 14%);
          img {
            width: 60px;
            height: 65px;
          }
        }
        .left-number {
          overflow: hidden;
          font-family: DIN;
          font-size: 62px;
        }
      }
      .item-center {
        display: flex;
        flex-wrap: wrap;
        place-content: space-between space-between;
        height: 100%;
        .traffic-box {
          box-sizing: border-box;
          display: flex;
          flex-direction: column;
          width: 47%;
          height: 48%;
          padding: 25px;
          margin-bottom: 10px;
          border-radius: 30px;
          .traffic-img {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 70px;
            height: 70px;
            margin-bottom: 10px;
            background-color: #ffffff;
            border-radius: 19px;
          }
        }
        img {
          width: 33px;
          height: 33px;
        }
        .item-value {
          margin-bottom: 4px;
          font-family: DIN;
          font-size: 28px;
          font-weight: bold;
          color: #1a1a37;
        }
        .traffic-name {
          overflow: hidden;
          font-family: DIN;
          font-size: 15px;
          color: #1a1a37;
          white-space: nowrap;
        }
        .gitee-traffic {
          background: #e8faea url("./images/1-bg.png");
          background-size: 100% 100%;
        }
        .gitHub-traffic {
          background: #e7e1fb url("./images/2-bg.png");
          background-size: 100% 100%;
        }
        .today-traffic {
          background: #fdf3e9 url("./images/3-bg.png");
          background-size: 100% 100%;
        }
        .yesterday-traffic {
          background: #f0f5fb url("./images/4-bg.png");
          background-size: 100% 100%;
        }
      }
      .item-right {
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 430px;
        border: 1px solid var(--el-border-color);
        border-radius: 25px;
        .echarts-title {
          padding: 15px 20px;
          font-family: DIN;
          font-size: 18px;
          font-weight: bold;
          border-bottom: 1px solid var(--el-border-color);
        }
        .book-echarts {
          flex: 1;
          width: 100%;
        }
      }
    }
  }

  .bottom-box {
    position: relative;
    padding: 20px 0 0;
    background-color: #fff;
    margin: 10px 10px 10px 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    height: 700px;
    .bottom-title {
      position: absolute;
      top: 25px;
      left: 50px;
      font-family: DIN;
      font-size: 18px;
      font-weight: bold;
    }
    .bottom-tabs {
      padding: 0 50px;
    }
    .curve-echarts {
      box-sizing: border-box;
      height: 400px;
      padding: 0 50px;
      margin-top: 20px;
    }
  }
}

</style>
